home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
BBS-Archive
/
Comm
/
term-source.lha
/
Extras
/
Source
/
term-Source.lha
/
TerminalPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-17
|
17KB
|
690 lines
/*
** TerminalPanel.c
**
** Editing panel for terminal configuration
**
** Copyright © 1990-1995 by Olaf `Olsen' Barthel
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_EMULATIONTYPE=1, GAD_EMULATIONLIBRARY, GAD_COLUMNS, GAD_LINES,
GAD_KEYMAP, GAD_TEXTFONT, GAD_FONTMODE, GAD_EMULATIONTASK, GAD_IBMFONT,
GAD_USE, GAD_CANCEL, GAD_DEFAULT, GAD_PAGER, GAD_PAGEGROUP
};
STATIC LONG LocalMaxColumns,
LocalMaxLines;
STATIC STRPTR __saveds
ShowColumn(struct Gadget *SomeGadget,WORD Level)
{
STATIC UBYTE Buffer[10];
if(Level == LocalMaxColumns + 1)
strcpy(Buffer,LocaleString(MSG_TERMINALPANEL_MAXIMUM_TXT));
else
SPrintf(Buffer,LocaleBase ? "%9lD" : "%9ld",Level);
return(Buffer);
}
STATIC STRPTR __saveds
ShowLine(struct Gadget *SomeGadget,WORD Level)
{
STATIC UBYTE Buffer[10];
if(Level == LocalMaxLines + 1)
strcpy(Buffer,LocaleString(MSG_TERMINALPANEL_MAXIMUM_TXT));
else
SPrintf(Buffer,LocaleBase ? "%9lD" : "%9ld",Level);
return(Buffer);
}
/* SelectKeymap(UBYTE *Name,struct Window *ParentWindow):
*
* Select a new keymap file using the asl.library file requester.
*/
STATIC BYTE __regargs
SelectKeymap(UBYTE *Name,struct Window *ParentWindow)
{
struct FileRequester *AslFileRequest;
struct TagItem DimensionTags[5];
UBYTE *File,*Temp;
BYTE NewMap = FALSE;
File = Name;
strcpy(SharedBuffer,File);
Temp = PathPart(SharedBuffer);
Temp[0] = 0;
if(!SharedBuffer[0])
{
APTR OldPtr = ThisProcess -> pr_WindowPtr;
BPTR FileLock;
ThisProcess -> pr_WindowPtr = (APTR)-1;
if(FileLock = Lock("KEYMAPS:",ACCESS_READ))
{
strcpy(SharedBuffer,"KEYMAPS:");
UnLock(FileLock);
}
else
strcpy(SharedBuffer,"Devs:Keymaps");
ThisProcess -> pr_WindowPtr = OldPtr;
}
File = FilePart(File);
if(AslFileRequest = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
ASL_Window, ParentWindow,
ASL_File, File,
ASL_Dir, SharedBuffer,
ASL_Hail, LocaleString(MSG_TERMINALPANEL_SELECT_KEYMAP_TXT),
ASL_FuncFlags, FILF_NEWIDCMP,
ASL_OKText, LocaleString(MSG_GLOBAL_SELECT_TXT),
TAG_MORE,GetDimensionTags(ParentWindow,DimensionTags)))
{
if(AslRequestTags(AslFileRequest,TAG_DONE))
{
STRPTR FileName;
if(AslFileRequest -> rf_NumArgs > 1 && AslFileRequest -> rf_ArgList)
FileName = AslFileRequest -> rf_ArgList -> wa_Name;
else
FileName = AslFileRequest -> rf_File;
if(FileName[0])
{
PutDimensionTags(ParentWindow,AslFileRequest -> rf_LeftEdge,AslFileRequest -> rf_TopEdge,AslFileRequest -> rf_Width,AslFileRequest -> rf_Height);
strcpy(SharedBuffer,AslFileRequest -> rf_Dir);
if(!AddPart(SharedBuffer,FileName,MAX_FILENAME_LENGTH))
strcpy(SharedBuffer,FileName);
if(Stricmp(SharedBuffer,Name))
{
strcpy(Name,SharedBuffer);
NewMap = TRUE;
}
}
}
FreeAslRequest(AslFileRequest);
}
return(NewMap);
}
BYTE __regargs
TerminalPanel(struct Configuration *LocalConfig,BYTE *Default)
{
STATIC LONG PageTitleID[5] =
{
MSG_V36_1020,
MSG_V36_1021,
MSG_V36_1024,
MSG_V36_1025,
-1
};
STATIC BYTE InitialPage = 0;
struct LayoutHandle *Handle;
BYTE Cancel = FALSE;
STRPTR PageTitle[5];
LocalizeStringTable(PageTitle,PageTitleID);
SaveConfig(LocalConfig,PrivateConfig);
if(Handle = LT_CreateHandleTags(Window -> WScreen,
LH_LocaleHook, &LocaleHook,
LH_ExitFlush, FALSE,
TAG_DONE))
{
struct Window *PanelWindow;
LONG LocalColumns,
LocalLines;
UBYTE FontName[MAX_FILENAME_LENGTH],
IBMName[MAX_FILENAME_LENGTH];
BuildFontName(FontName,LocalConfig -> TerminalConfig -> TextFontName,LocalConfig -> TerminalConfig -> TextFontHeight);
BuildFontName(IBMName,LocalConfig -> TerminalConfig -> IBMFontName,LocalConfig -> TerminalConfig -> IBMFontHeight);
if(LocalConfig != Config)
{
LocalMaxColumns = 132;
LocalMaxLines = 64;
}
else
{
LONG Width,
Height;
if(Screen)
{
struct Rectangle DisplayClip;
if(LocalConfig -> ScreenConfig)
{
Width = LocalConfig -> ScreenConfig -> DisplayWidth;
Height = LocalConfig -> ScreenConfig -> DisplayHeight;
QueryOverscan(LocalConfig -> ScreenConfig -> DisplayMode,&DisplayClip,LocalConfig -> ScreenConfig -> OverscanType);
}
else
{
Width = LocalConfig -> ScreenConfig -> DisplayWidth;
Height = LocalConfig -> ScreenConfig -> DisplayHeight;
QueryOverscan(LocalConfig -> ScreenConfig -> DisplayMode,&DisplayClip,LocalConfig -> ScreenConfig -> OverscanType);
}
if(!Width)
Width = DisplayClip . MaxX - DisplayClip . MinX + 1;
if(!Height)
Height = DisplayClip . MaxY - DisplayClip . MinY + 1;
}
else
{
Width = Window -> WScreen -> Width - Window -> WScreen -> WBorLeft - Window -> WScreen -> WBorRight;
Height = Window -> WScreen -> Height - Window -> WScreen -> WBorTop - Window -> WScreen -> WBorBottom - Window -> WScreen -> Font -> ta_YSize - 1;
if(!StatusWindow)
Height -= StatusDisplayHeight;
if(ChatMode)
Height -= UserFontHeight + 2;
}
if(WindowWidth > Width)
Width = WindowWidth;
if(WindowHeight > Height)
Height = WindowHeight;
LocalMaxColumns = Width / TextFontWidth;
LocalMaxLines = Height / TextFontHeight;
if(LocalMaxColumns < 20)
LocalMaxColumns = 20;
if(LocalMaxLines < 20)
LocalMaxLines = 20;
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type,VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_ID, GAD_PAGER,
LA_LabelID, MSG_XFER_PAGE_TXT,
GTCY_Labels, PageTitle,
LACY_AutoPageID,GAD_PAGEGROUP,
LACY_TabKey, TRUE,
LA_BYTE, &InitialPage,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
LA_ID, GAD_PAGEGROUP,
LAGR_Frame, TRUE,
LAGR_ActivePage,InitialPage,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelID, MSG_TERMINALPANEL_EMULATION_GAD,
LA_ID, GAD_EMULATIONTYPE,
LA_BYTE, &LocalConfig -> TerminalConfig -> EmulationMode,
LACY_FirstLabel,MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT,
LACY_LastLabel, MSG_TERMINALPANEL_EMULATION_HEX_TXT,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_TERMINALPANEL_EMULATION_NAME_GAD,
LA_Chars, 20,
LA_ID, GAD_EMULATIONLIBRARY,
LA_STRPTR, LocalConfig -> TerminalConfig -> EmulationFileName,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
LAST_Picker, TRUE,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL,
TAG_DONE);
LT_New(Handle,
LA_Type, CHECKBOX_KIND,
LA_LabelID, MSG_EMULATIONPANEL_USE_TERMINAL_TASK_TXT,
LA_BYTE, &LocalConfig -> TerminalConfig -> UseTerminalTask,
LA_ID, GAD_EMULATIONTASK,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelID, MSG_TERMINALPANEL_BELL_GAD,
LA_BYTE, &LocalConfig -> TerminalConfig -> BellMode,
LACY_FirstLabel,MSG_TERMINALPANEL_BELL_IGNORE_TXT,
LACY_LastLabel, MSG_TERMINALPANEL_BELL_DEFAULT_TXT,
TAG_DONE);
if(LocalConfig -> TerminalConfig -> NumColumns < 20)
LocalColumns = LocalMaxColumns + 1;
else
LocalColumns = LocalConfig -> TerminalConfig -> NumColumns;
LT_New(Handle,
LA_Type, SliderType,
LA_LabelID, MSG_TERMINALPANEL_NUMCOLUMNS_GAD,
LA_ID, GAD_COLUMNS,
LA_LONG, &LocalColumns,
GTSL_Min, 20,
GTSL_Max, LocalMaxColumns + 1,
GTSL_DispFunc, ShowColumn,
GTSL_LevelFormat, "%s",
TAG_DONE);
if(LocalConfig -> TerminalConfig -> NumLines < 20)
LocalLines = LocalMaxLines + 1;
else
LocalLines = LocalConfig -> TerminalConfig -> NumLines;
LT_New(Handle,
LA_Type, SliderType,
LA_LabelID, MSG_TERMINALPANEL_NUMLINES_GAD,
LA_LONG, &LocalLines,
LA_ID, GAD_LINES,
GTSL_Min, 20,
GTSL_Max, LocalMaxLines + 1,
GTSL_DispFunc, ShowLine,
GTSL_LevelFormat, "%s",
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_TERMINALPANEL_KEYMAP_FILE_GAD,
LA_Chars, 20,
LA_ID, GAD_KEYMAP,
LA_STRPTR, LocalConfig -> TerminalConfig -> KeyMapFileName,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
LAST_Picker, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, TEXT_KIND,
LA_LabelID, MSG_TERMINALPANEL_TEXT_FONT_GAD,
LA_Chars, 20,
LA_ID, GAD_TEXTFONT,
GTTX_Text, FontName,
GTTX_Border, TRUE,
LATX_Picker, TRUE,
LATX_LockSize, TRUE,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL,
TAG_DONE);
LT_New(Handle,
LA_Type, TEXT_KIND,
LA_LabelID, MSG_TERMINALPANEL_IBM_FONT_GAD,
LA_Chars, 20,
LA_ID, GAD_IBMFONT,
GTTX_Text, IBMName,
GTTX_Border, TRUE,
LATX_Picker, TRUE,
LATX_LockSize, TRUE,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL,
TAG_DONE);
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelID, MSG_TERMINALPANEL_FONT_GAD,
LA_ID, GAD_FONTMODE,
LA_BYTE, &LocalConfig -> TerminalConfig -> FontMode,
LACY_FirstLabel,MSG_TERMINALPANEL_FONT_STANDARD_TXT,
LACY_LastLabel, MSG_TERMINALPANEL_FONT_PC_RAW,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, HORIZONTAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelID, MSG_TERMINALPANEL_SEND_CR_GAD,
LA_BYTE, &LocalConfig -> TerminalConfig -> SendCR,
GTCY_Labels, EOL_Labels,
TAG_DONE);
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelID, MSG_TERMINALPANEL_SEND_LF_GAD,
LA_BYTE, &LocalConfig -> TerminalConfig -> SendLF,
GTCY_Labels, EOL_Labels,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, YBAR_KIND,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelID, MSG_TERMINALPANEL_RECEIVE_CR_GAD,
LA_BYTE, &LocalConfig -> TerminalConfig -> ReceiveCR,
GTCY_Labels, EOL_Labels,
TAG_DONE);
LT_New(Handle,
LA_Type, CYCLE_KIND,
LA_LabelID, MSG_TERMINALPANEL_RECEIVE_LF_GAD,
LA_BYTE, &LocalConfig -> TerminalConfig -> ReceiveLF,
GTCY_Labels, EOL_Labels,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,LA_Type,XBAR_KIND,LAXB_FullSize,TRUE,TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,LA_Type,HORIZONTAL_KIND,
LAGR_SameSize, TRUE,
LAGR_Spread, TRUE,
TAG_DONE);
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_USE_GAD,
LA_ID, GAD_USE,
LABT_ReturnKey, TRUE,
LABT_ExtraFat, TRUE,
TAG_DONE);
if(Default)
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_DEFAULT_GAD,
LA_ID, GAD_DEFAULT,
LABT_ExtraFat, TRUE,
TAG_DONE);
}
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_CANCEL_GAD,
LA_ID, GAD_CANCEL,
LABT_EscKey, TRUE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_TERMINALPANEL_TERMINAL_PREFERENCES_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
LAWN_HelpHook, &GuideHook,
LAWN_Parent, Window,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_DragBar, TRUE,
WA_RMBTrap, TRUE,
WA_Activate, TRUE,
TAG_DONE))
{
struct IntuiMessage *Message;
BOOLEAN Done = FALSE;
ULONG MsgClass,
MsgQualifier;
UWORD MsgCode;
struct Gadget *MsgGadget;
UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
GuideContext(CONTEXT_TERMINAL);
PushWindow(PanelWindow);
LT_ShowWindow(Handle,TRUE);
do
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
{
SaveConfig(PrivateConfig,LocalConfig);
break;
}
while(Message = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort))
{
MsgClass = Message -> Class;
MsgQualifier = Message -> Qualifier;
MsgCode = Message -> Code;
MsgGadget = (struct Gadget *)Message -> IAddress;
GT_ReplyIMsg(Message);
LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
if(MsgClass == IDCMP_CLOSEWINDOW)
{
SaveConfig(PrivateConfig,LocalConfig);
Done = TRUE;
}
if(MsgClass == IDCMP_GADGETUP)
{
switch(MsgGadget -> GadgetID)
{
case GAD_USE:
LT_UpdateStrings(Handle);
LocalConfig -> TerminalConfig -> NumColumns = LocalColumns % (LocalMaxColumns + 1);
LocalConfig -> TerminalConfig -> NumLines = LocalLines % (LocalMaxLines + 1);
if(!LocalConfig -> TerminalConfig -> EmulationFileName[0] && LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
LocalConfig -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
Done = TRUE;
break;
case GAD_EMULATIONTYPE:
LT_SetAttributes(Handle,GAD_TEXTFONT,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL,
TAG_DONE);
LT_SetAttributes(Handle,GAD_IBMFONT,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL,
TAG_DONE);
LT_SetAttributes(Handle,GAD_FONTMODE,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL,
TAG_DONE);
LT_SetAttributes(Handle,GAD_EMULATIONLIBRARY,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL,
TAG_DONE);
LT_SetAttributes(Handle,GAD_EMULATIONTASK,
GA_Disabled, LocalConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL,
TAG_DONE);
break;
case GAD_CANCEL:
SaveConfig(PrivateConfig,LocalConfig);
Cancel = Done = TRUE;
break;
case GAD_DEFAULT:
*Default = TRUE;
Done = TRUE;
break;
}
}
if(MsgClass == IDCMP_IDCMPUPDATE)
{
switch(MsgGadget -> GadgetID)
{
case GAD_EMULATIONLIBRARY:
LT_LockWindow(PanelWindow);
strcpy(DummyBuffer,(STRPTR)LT_GetAttributes(Handle,GAD_EMULATIONLIBRARY,TAG_DONE));
strcpy(SharedBuffer,DummyBuffer);
if(PickFile(PanelWindow,"Libs:","xem#?.library",LocaleString(MSG_TERMINALPANEL_SELECT_EMULATOR_TXT),SharedBuffer,NT_LIBRARY))
{
if(Stricmp(SharedBuffer,DummyBuffer))
LT_SetAttributes(Handle,GAD_EMULATIONLIBRARY,GTST_String,SharedBuffer,TAG_DONE);
}
LT_ShowWindow(Handle,TRUE);
LT_UnlockWindow(PanelWindow);
break;
case GAD_KEYMAP:
LT_LockWindow(PanelWindow);
strcpy(DummyBuffer,(STRPTR)LT_GetAttributes(Handle,GAD_KEYMAP,TAG_DONE));
if(SelectKeymap(DummyBuffer,PanelWindow))
LT_SetAttributes(Handle,GAD_KEYMAP,GTST_String,SharedBuffer,TAG_DONE);
LT_UnlockWindow(PanelWindow);
break;
case GAD_TEXTFONT:
LT_LockWindow(PanelWindow);
if(PickFont(PanelWindow,LocalConfig -> TerminalConfig -> TextFontName,&LocalConfig -> TerminalConfig -> TextFontHeight,TRUE))
{
BuildFontName(FontName,LocalConfig -> TerminalConfig -> TextFontName,LocalConfig -> TerminalConfig -> TextFontHeight);
LT_SetAttributes(Handle,GAD_TEXTFONT,
GTTX_Text, FontName,
TAG_DONE);
}
LT_UnlockWindow(PanelWindow);
break;
case GAD_IBMFONT:
LT_LockWindow(PanelWindow);
if(PickFont(PanelWindow,LocalConfig -> TerminalConfig -> IBMFontName,&LocalConfig -> TerminalConfig -> IBMFontHeight,TRUE))
{
BuildFontName(IBMName,LocalConfig -> TerminalConfig -> IBMFontName,LocalConfig -> TerminalConfig -> IBMFontHeight);
LT_SetAttributes(Handle,GAD_IBMFONT,
GTTX_Text, IBMName,
TAG_DONE);
}
LT_UnlockWindow(PanelWindow);
break;
}
}
}
}
while(!Done);
PopWindow();
}
LT_DeleteHandle(Handle);
}
if(Default)
return((BYTE)(!Cancel));
else
return((BYTE)memcmp(PrivateConfig -> TerminalConfig,LocalConfig -> TerminalConfig,sizeof(struct TerminalSettings)));
}